<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Comparison to Other Libraries</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Chapter 1. Boost.JSON">
<link rel="up" href="../index.html" title="Chapter 1. Boost.JSON">
<link rel="prev" href="benchmarks.html" title="Benchmarks">
<link rel="next" href="quickref.html" title="Reference">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="benchmarks.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="quickref.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="json.comparison"></a><a class="link" href="comparison.html" title="Comparison to Other Libraries">Comparison to Other Libraries</a>
</h2></div></div></div>
<p>
      There exist many C++ JSON libraries, but two are particularly noteworthy for
      the purpose of comparison: <a href="https://rapidjson.org/" target="_top">RapidJSON</a>
      and <a href="https://nlohmann.github.io/json/" target="_top">JSON for Modern C++</a>
      (referred to herein as nlohmann's JSON, or nlohmann).
    </p>
<h4>
<a name="json.comparison.h0"></a>
      <span class="phrase"><a name="json.comparison.comparison_to_nlohmann_json"></a></span><a class="link" href="comparison.html#json.comparison.comparison_to_nlohmann_json">Comparison
      to nlohmann JSON</a>
    </h4>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
          Value Type: <a href="https://github.com/nlohmann/json/blob/00cb98a3d170161711ab912ae6acefba31f29f75/include/nlohmann/json.hpp#L165" target="_top"><code class="computeroutput"><span class="identifier">nlohmann</span><span class="special">::</span><span class="identifier">basic_json</span></code></a>
        </li></ul></div>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span>
    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span><span class="special">,</span> <span class="keyword">typename</span><span class="special">,</span> <span class="keyword">typename</span><span class="special">...&gt;</span> <span class="keyword">class</span> <span class="identifier">ObjectType</span><span class="special">,</span>
    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span><span class="special">,</span> <span class="keyword">typename</span><span class="special">...&gt;</span> <span class="keyword">class</span> <span class="identifier">ArrayType</span><span class="special">,</span>
    <span class="keyword">class</span> <span class="identifier">StringType</span><span class="special">,</span>
    <span class="keyword">class</span> <span class="identifier">BooleanType</span><span class="special">,</span>
    <span class="keyword">class</span> <span class="identifier">NumberIntegerType</span><span class="special">,</span>
    <span class="keyword">class</span> <span class="identifier">NumberUnsignedType</span><span class="special">,</span>
    <span class="keyword">class</span> <span class="identifier">NumberFloatType</span><span class="special">,</span>
    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span><span class="special">&gt;</span> <span class="keyword">class</span> <span class="identifier">AllocatorType</span><span class="special">,</span>
    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span><span class="special">,</span> <span class="keyword">typename</span> <span class="special">=</span> <span class="keyword">void</span><span class="special">&gt;</span> <span class="keyword">class</span> <span class="identifier">JSONSerializer</span>
    <span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">basic_json</span>
<span class="special">{</span>
  <span class="keyword">private</span><span class="special">:</span>
    <span class="special">....</span>
    <span class="keyword">friend</span> <span class="special">::</span><span class="identifier">nlohmann</span><span class="special">::</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">parser</span><span class="special">&lt;</span><span class="identifier">basic_json</span><span class="special">&gt;;</span>
    <span class="keyword">friend</span> <span class="special">::</span><span class="identifier">nlohmann</span><span class="special">::</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">serializer</span><span class="special">&lt;</span><span class="identifier">basic_json</span><span class="special">&gt;;</span>
<span class="special">...</span>
</pre>
<p>
      This library adopts a "kitchen sink" approach. It contains a wealth
      of features, even those with niche uses. Its weakness is that the many template
      parameters, while allowing for configurability, inhibit the best possible optimizations.
      The consequence is that the library performs poorly. The ability to configure
      every aspect of the value type has the paradoxical effect of making it less
      suitable as a vocabulary type.
    </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
          <span class="red">✘</span> <code class="computeroutput"><span class="identifier">basic_json</span></code>
          is a class template. Libraries must agree on the choices of template parameters
          to be interoperable.
        </li>
<li class="listitem">
          <span class="red">✘</span> Too much customization. We struggle
          to see a use case for making <code class="computeroutput"><span class="identifier">BooleanType</span></code>
          anything other than <code class="computeroutput"><span class="keyword">bool</span></code>.
        </li>
<li class="listitem">
          <span class="red">✘</span> Poor separation of concerns. The
          <code class="computeroutput"><span class="identifier">basic_json</span></code> container declaration
          needlessly conflates parsing and serialization APIs.
        </li>
<li class="listitem">
          <span class="red">✘</span> Limited allocator support. Only stateless
          allocators are allowed, which rules out the most important type of allocator,
          a local arena-based implementation.
        </li>
<li class="listitem">
          <span class="red">✘</span> No incremental parsing, no incremental
          serialization.
        </li>
<li class="listitem">
          <span class="red">✘</span> Slow parsing and serialization performance.
        </li>
<li class="listitem">
          <span class="green">✔</span> Full-featured, including JSON Pointer,
          CBOR, and others.
        </li>
</ul></div>
<h4>
<a name="json.comparison.h1"></a>
      <span class="phrase"><a name="json.comparison.comparison_to_rapidjson"></a></span><a class="link" href="comparison.html#json.comparison.comparison_to_rapidjson">Comparison
      to RapidJSON</a>
    </h4>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
          Value Type: <a href="https://github.com/Tencent/rapidjson/blob/bb5f966b9939d6cdfbac3462a0410e185099b3af/include/rapidjson/document.h#L608" target="_top"><code class="computeroutput"><span class="identifier">rapidjson</span><span class="special">::</span><span class="identifier">GenericValue</span></code></a>
        </li></ul></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Encoding</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Allocator</span> <span class="special">=</span> <span class="identifier">MemoryPoolAllocator</span><span class="special">&lt;&gt;</span> <span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">GenericValue</span><span class="special">;</span>

<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">bool</span> <span class="identifier">Const</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">ValueT</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">GenericArray</span><span class="special">;</span>

<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">bool</span> <span class="identifier">Const</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">ValueT</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">GenericObject</span><span class="special">;</span>
</pre>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
          <span class="red">✘</span> The value type is not regular. Assignment
          is destructive, performing <code class="computeroutput"><span class="identifier">a</span>
          <span class="special">=</span> <span class="identifier">b</span></code>
          is equivalent to <code class="computeroutput"><span class="identifier">a</span> <span class="special">=</span>
          <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">b</span><span class="special">)</span></code>. No
          copy construction or copy assignment allowed.
        </li>
<li class="listitem">
          <span class="red">✘</span> Object types have no hash table or
          index to reduce the cost of lookups.
        </li>
<li class="listitem">
          <span class="red">✘</span> Allocators have reference semantics.
          Problems with lifetime are easily encountered.
        </li>
<li class="listitem">
          <span class="red">✘</span> The interface of the array and object
          types are considerably different from their standard library equivalents,
          and not idiomatic.
        </li>
<li class="listitem">
          <span class="red">✘</span> No incremental parsing, no incremental
          serialization.
        </li>
<li class="listitem">
          <span class="green">✔</span> Parsing and serialization performance
          is better than most other libraries.
        </li>
</ul></div>
<h4>
<a name="json.comparison.h2"></a>
      <span class="phrase"><a name="json.comparison.comparison_to_simd_json"></a></span><a class="link" href="comparison.html#json.comparison.comparison_to_simd_json">Comparison
      to SIMD JSON</a>
    </h4>
<p>
      <a href="https://github.com/lemire/simdjson" target="_top">https://github.com/lemire/simdjson</a>
    </p>
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">ParsedJson</span><span class="special">;</span>
</pre>
<p>
      This is quite an interesting data structure, which is optimized to work well
      with the SIMD parser. It makes very good design choices for the intended use-case.
      However it is not well suited as a vocabulary type due to the necessary limitations.
    </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
          <span class="red">✘</span> Sequential access only, via <code class="computeroutput"><span class="identifier">ParsedJson</span><span class="special">::</span><span class="identifier">BasicIterator</span></code>
        </li>
<li class="listitem">
          <span class="red">✘</span> Read-only, can only be populated by
          the provided SIMD JSON parser.
        </li>
<li class="listitem">
          <span class="green">✔</span> The fastest available JSON parser.
        </li>
</ul></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2019, 2020 Vinnie Falco<br>Copyright © 2020 Krystian Stasiowski<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="benchmarks.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="quickref.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
